package com.douqu.game.activity.gui.component.impl;


import com.douqu.game.activity.GameServer;
import com.douqu.game.activity.entity.camp.CampPlayer;
import com.douqu.game.activity.gui.MainFrame;

import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.util.Map;


public class LabelComponent extends Component
{

	private Container container;
	
	public void setJFrame(JFrame frame)
	{
		container = frame.getContentPane();
	}

	
	public JLabel lPlayerCount; //玩家数量
	
	public JLabel lServerStartTime;
	
	public JLabel lServerTime;
	
	public JLabel lServerName;
	
	public JLabel [] lJobs;
	
	public JLabel lMaxMem;
	
	public JLabel lCurrMem;
	
	public LabelComponent()
	{
		lServerStartTime = new JLabel();
		lServerStartTime.setForeground(Color.WHITE);
		lServerStartTime.setBounds(20, MainFrame.HEIGHT-65, 300, 50);
		
		lServerTime = new JLabel("");
		lServerTime.setForeground(Color.WHITE);
		lServerTime.setBounds(MainFrame.WIDTH-160,MainFrame.HEIGHT-65, 300, 50);
		
		lPlayerCount = new JLabel();
		lPlayerCount.setForeground(Color.WHITE);
		lPlayerCount.setBounds(MainFrame.WIDTH-170,30, 200, 50);
		
		lMaxMem = new JLabel();
		lMaxMem.setForeground(Color.WHITE);
		lMaxMem.setBounds(MainFrame.WIDTH-170,270,300,50);
		
		lCurrMem = new JLabel();
		lCurrMem.setForeground(Color.WHITE);
		lCurrMem.setBounds(MainFrame.WIDTH-170,300,300,50);
		
//		lJobs = new JLabel[GameServer.JOB_COUNT];
//
//		for(int i = 0 ; i < GameServer.JOB_COUNT ; i ++)
//		{
//			lJobs[i] = new JLabel();
//			lJobs[i].setForeground(Color.WHITE);
//			lJobs[i].setBounds(MainFrame.WIDTH-145,50+(i*15), 200, 50);
//		}
		
		lServerName = new JLabel("Game Server");
		lServerName.setFont(new Font("TimesRoman",Font.BOLD,20));
		lServerName.setForeground(Color.WHITE);
		lServerName.setBounds(20, 0, 500, 50);
	}
	
	
	public void addToFrame()
	{
		container.add(lServerStartTime);
		container.add(lServerTime);
		container.add(lPlayerCount);
		container.add(lMaxMem);
		container.add(lCurrMem);
		container.add(lServerName);
		
		
//		for(int i = 0 ; i < GameServer.JOB_COUNT ; i ++)
//		{
//			container.add(lJobs[i]);
//		}
	}


	public void updatePlayerCount()
	{
		StringBuffer buffer = new StringBuffer();

		Map<Integer, List<CampPlayer>> map = GameServer.getInstance().getActivityCampManager().getCampPlayerMap();
		int totalCount = 0;
		for(Map.Entry<Integer, List<CampPlayer>> entry : map.entrySet())
		{
			totalCount += entry.getValue().size();
		}

		buffer.append("MatchCount:   ");
		buffer.append(totalCount);
		buffer.append(" / ");
		buffer.append(GameServer.getInstance().getActivityCampManager().getPlayerList().size());

		lPlayerCount.setText(buffer.toString());
	}


	

}
